<template>
  <div class="app-container mod-hot-search">
    <!-- 搜索相关区域 -->
    <div class="filter-container">
      <el-form :inline="true" :model="pageQuery" class="demo-form-inline">
        <el-form-item label="吧台编号">
          <el-input
            v-model="pageQuery.number"
            size="mini"
            placeholder="请输入集合编号"
          />
        </el-form-item>
        <el-form-item label="投放区域">
          <el-select
            v-model="pageQuery.barCounterShopId"
            size="mini"
            placeholder="请选择投放区域"
            clearable
          >
            <el-option
              v-for="(item, index) in barCounterShopList"
              :key="index"
              :label="item.barCounterRegion"
              :value="item.barCounterShopId"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="吧台类型">
          <el-select
            v-model="pageQuery.type"
            size="mini"
            placeholder="请选择吧台类型"
            clearable
          >
            <el-option label="全部" value="" />
            <el-option label="自营" value="1" />
            <el-option label="联营" value="2" />
          </el-select>
        </el-form-item>
        <el-form-item label="状态">
          <el-select
            v-model="pageQuery.status"
            size="mini"
            placeholder="请选择状态"
            clearable
          >
            <el-option label="全部" value="" />
            <el-option label="正常" value="1" />
            <el-option label="离线" value="2" />
          </el-select>
        </el-form-item>
        <el-form-item label="创建时间">
          <el-date-picker
            v-model="pageQuery.createTime"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            size="mini"
            icon="el-icon-search"
            @click="getPage()"
            >查询</el-button
          >
          <el-button
            size="mini"
            icon="el-icon-delete"
            @click="clearSearchInfo()"
            >清空</el-button
          >
        </el-form-item>
      </el-form>
      <el-button
        v-permission="['']"
        size="mini"
        icon="el-icon-plus"
        type="primary"
        class="filter-item"
        @click="addOrUpdateHandle()"
        >新增</el-button
      >
    </div>
    <!-- 列表相关区域 -->
    <el-table
      v-loading="pageLoading"
      :data="pageVO.list"
      border
      fit
      highlight-current-row
      style="width: 100%"
    >
      <!-- 吧台编号 -->
      <el-table-column label="吧台编号" prop="title" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.number }}</span>
        </template>
      </el-table-column>
      <!-- 投放区域 -->
      <el-table-column label="投放区域" prop="content" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.barCounterRegion }}</span>
        </template>
      </el-table-column>
      <!-- 吧台类型 -->
      <el-table-column label="吧台类型" prop="content" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.type == 1 ? '自营' : '联营' }}</span>
        </template>
      </el-table-column>
      <!-- 吧台营销 -->
      <el-table-column label="吧台销量" prop="content" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.totalCount }}</span>
        </template>
      </el-table-column>
      <!-- 创建时间 -->
      <el-table-column
        :label="$t('platform.hotSearch.createDate')"
        prop="createTime"
        align="center"
      >
        <template slot-scope="{ row }">
          <span>{{ row.createTime }}</span>
        </template>
      </el-table-column>
      <!-- 状态 1正常 2离线 -->
      <el-table-column
        :label="$t('platform.hotSearch.status')"
        prop="status"
        align="center"
      >
        <template slot-scope="{ row }">
          <!-- <span>{{ row.status }}</span> -->
          <el-tag v-if="row.status === 0" size="small" type="danger">{{
            "未启用"
          }}</el-tag>
          <el-tag v-else size="small">{{ "启用" }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        :label="$t('table.actions')"
        align="center"
        width="320"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="{ row }">
          <el-button
            v-permission="['']"
            type="primary"
            size="mini"
            icon="el-icon-edit-outline"
            @click="handleEdit(row.barCounterId)"
          >
            编辑
          </el-button>
          <el-button
            v-permission="['']"
            type="primary"
            size="mini"
            icon="el-icon-view"
            @click="handleView(row.barCounterId)"
          >
            查看
          </el-button>
          <el-button
            v-permission="['']"
            type="primary"
            size="mini"
            icon="el-icon-document-copy"
            @click="handleCopy(row.barCounterId)"
          >
            复制
          </el-button>
          <el-button
            v-permission="['']"
            type="danger"
            size="mini"
            icon="el-icon-delete-solid"
            @click="handleDel(row.barCounterId)"
          >
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页条 -->
    <pagination
      v-show="pageVO.total > 0"
      :total="pageVO.total"
      :page.sync="pageQuery.pageNum"
      :limit.sync="pageQuery.pageSize"
      @pagination="getPage()"
    />
    <!-- 弹窗, 新增 / 修改 -->
  </div>
</template>
  
  <script>
import permission from "@/directive/permission/index.js";
import Pagination from "@/components/Pagination";
import * as api from "@/api/selfoperated/index";

export default {
  name: "",
  components: { Pagination },
  directives: { permission },
  data() {
    return {
      // 查询的参数
      pageQuery: {
        pageSize: 10,
        pageNum: 1
      },
      // 返回参数
      pageVO: {
        list: [], // 返回的列表
        total: 0, // 一共多少条数据
        pages: 0, // 一共多少页
      },
      // loading
      pageLoading: false,
      addOrUpdateVisible: false,
      barCounterShopList: [],
    };
  },
  mounted() {
    this.getPage();
    this.getBarCounterShopList()
  },
  methods: {
    getPage() {
      this.pageLoading = true;
      this.pageQuery.number ? this.pageQuery.number : delete this.pageQuery.number
      this.pageQuery.barCounterShopId ? this.pageQuery.barCounterShopId : delete this.pageQuery.barCounterShopId
      this.pageQuery.status ? this.pageQuery.status : delete this.pageQuery.status
      this.pageQuery.type ? this.pageQuery.type : delete this.pageQuery.type
      this.pageQuery.createTime ? this.pageQuery.createTime : delete this.pageQuery.createTime
      api.getPage({ ...this.pageQuery }).then((pageVO) => {
        this.pageVO = pageVO;
        this.pageLoading = false;
      });
    },
    getBarCounterShopList() {
      api.barCounterShopList().then(result=> {
        this.barCounterShopList = result
      })
    },
    addOrUpdateHandle() {
      this.$router.push("/barcounter/selfoperated/add");
    },
    handleEdit(id) {
      this.$router.push(`/barcounter/selfoperated/update?barCounterId=${id}`);
    },
    handleView(id) {
      this.$router.push(`/barcounter/selfoperated/detail?barCounterId=${id}`);
    },
    handleCopy(id) {
      this.$router.push(`/barcounter/selfoperated/add?barCounterId=${id}&&copy=copy`);
    },
    handleDel(id) {
      this.$confirm('请确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        api.del({barCounterId: id}).then(res => {
          this.$message({
            message: res || '操作成功',
            type: res ? 'error' : 'success',
            duration: 1500,
            onClose: () => this.getPage()
          })
        })
      }).catch(() => { })
    },
    clearSearchInfo() {
      // 若请求参数某项没值，则不传此参数
      this.pageQuery.pageNum = 1;
      this.pageQuery.pageSize = 10;
      delete this.pageQuery.number
      delete this.pageQuery.barCounterShopId
      delete this.pageQuery.status
      delete this.pageQuery.type
      delete this.pageQuery.createTime
      this.getPage();
    },
  },
};
</script>
  
<style lang="scss" scoped>
.mod-hot-search {
  .el-form--inline {
    .el-form-item {
      margin-right: 20px;
    }
  }
}
</style>
  